<!--
 * @Author: JiraiyaChen 979526234@qq.com
 * @Date: 2025-07-01 10:09:11
 * @LastEditors: JiraiyaChen 979526234@qq.com
 * @LastEditTime: 2025-07-28 13:36:12
 * @Description:  邀请招标 | 公开招标（500万元以上） | 公开招标（500万元以下）
-->

<template>
  <div class="review-report">
    <div class="title">
      <span>
        {{ componentName }}
      </span>
    </div>
    <el-descriptions :column="1" border>
      <el-descriptions-item label="项目名称">
        {{ staticData.projectName }}
      </el-descriptions-item>
      <el-descriptions-item label="项目编号">
        {{ staticData.projectNumber }}
      </el-descriptions-item>
      <el-descriptions-item label="招标公告刊登的媒体名称">
        <el-checkbox-group v-model="formData.mediaNameSelect">
          <el-checkbox v-for="item in mediaNameList" :key="item" :label="item" :value="item">{{ item }}</el-checkbox>
        </el-checkbox-group>
        <el-input v-model="formData.mediaNameInput" placeholder="请填写招标公告刊登的媒体名称" clearable />
      </el-descriptions-item>
      <el-descriptions-item label="开标日期">
        {{ storeData.openBidTime }}
      </el-descriptions-item>
      <el-descriptions-item label="开标地点">{{ storeData.openBidPlace }}</el-descriptions-item>
      <el-descriptions-item label="评标方法和标准">详见本项目采购文件</el-descriptions-item>
      <el-descriptions-item label="投标人名单,开标记录">详见开标记录表</el-descriptions-item>
      <el-descriptions-item label="评标委员会成员名单">
        {{ staticData.judgeInfo }}
      </el-descriptions-item>
    </el-descriptions>
    <el-descriptions direction="vertical" :column="1" border>
      <el-descriptions-item class-name="hidden-value" label-class-name="center-label" label="评标情况及说明" />
    </el-descriptions>
    <el-descriptions :column="1" border>
      <el-descriptions-item class-name="des-table" label="无效投标人名单">
        <CommonTable :table-data="staticData.invalidRecords" :columns="invalidRecordsColumns" />
      </el-descriptions-item>
    </el-descriptions>
    <el-descriptions :column="1" border>
      <el-descriptions-item class-name="des-table" label="中标候选人名单">
        <CommonTable :table-data="staticData.winBidResult" :columns="columns" />
      </el-descriptions-item>
    </el-descriptions>
    <el-descriptions :column="1" border>
      <el-descriptions-item label="废标原因">
        {{ staticData.deprecatedReason }}
      </el-descriptions-item>
    </el-descriptions>
    <el-descriptions :column="1" border>
      <el-descriptions-item label="评标委员会签字" />
      <el-descriptions-item
        label="其他需要说明的情况，包括评标过程中投标人根据评标委员会要求进行的澄清、说明或者补正，评标委员会成员的更换；评标事项讨论记录等"
      >
        <el-input
          v-model="formData.bidRemark"
          placeholder="请填写其他需要说明的情况"
          size="normal"
          type="textarea"
          :rows="5"
          clearable
        />
      </el-descriptions-item>
      <el-descriptions-item label="采购人采购结果确认">
        我单位同意确定排序第一的中标候选人为中标单位；
        <el-radio-group v-model="formData.baseRank">
          <el-radio value="是" label="是">是</el-radio>
          <el-radio value="否" label="否">否</el-radio>
        </el-radio-group>
        <el-input
          v-model="formData.baseRankRemark"
          placeholder="请填写采购人采购结果确认"
          size="normal"
          type="textarea"
          :rows="5"
          clearable
        />
        采购人代表签字：
      </el-descriptions-item>
    </el-descriptions>
    <div class="flex items-center justify-center mt-4">
      <el-button type="primary" @click="handleSave">提交</el-button>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import CommonTable from './CommonTable.vue'
import { handleMediaNameSelect, mediaNameList } from './data'
import { getReviewReportDynamicValue, updateReviewReportDynamicValue } from '@/api/review-report-generation'
const props = defineProps({
  componentName: {
    type: String,
    default: ''
  }
})
const columns = [
  {
    prop: 'supplierName',
    label: '投标人名称',
    width: 500
  },
  {
    prop: 'reviewPrice',
    label: '报价'
  }
]
const invalidRecordsColumns = [
  {
    prop: 'supplierNames',
    label: '投标人名称',
    width: 500
  },
  {
    prop: 'comment',
    label: '原因'
  }
]

onMounted(async () => {
  await initData()
})
const storeData = useProjectInfoStore().projectInfo

const staticData = ref({
  projectName: '',
  projectNumber: '',
  judgeInfo: '', // 评标委员会成员名单
  invalidRecords: [], // 无效投标人名单
  winBidResult: [], // 中标候选人名单
  deprecatedReason: '' // 废标原因
})
const formData = ref({
  mediaNameSelect: [], // 招标公告刊登的媒体名称
  mediaNameInput: '', // 招标公告刊登的媒体名称
  bidRemark: '', // 其他需要说明的情况
  baseRank: '', // 采购人采购结果确认-单选
  baseRankRemark: '' // 采购人采购结果确认-输入
})
const initData = async () => {
  const res: any = await getReviewReportDynamicValue()
  staticData.value.projectName = res.projectName
  staticData.value.projectNumber = res.projectNumber
  staticData.value.judgeInfo = res.judgeInfo
  staticData.value.invalidRecords = res.invalidRecords
  staticData.value.winBidResult = showWinBidResult(res.deprecated, res.winBidResult)
  staticData.value.deprecatedReason = res.deprecatedReason
  formData.value.mediaNameSelect = handleMediaNameSelect(res.mediaNameSelect)
  formData.value.mediaNameInput = res.mediaNameInput
  formData.value.bidRemark = res.bidRemark
  formData.value.baseRank = res.baseRank ?? ''
  formData.value.baseRankRemark = res.baseRankRemark
}
// 中标候选人名单 - 有 rankNo 才显示
const showWinBidResult = (deprecated, winBidResult) => {
  if (deprecated) {
    return []
  } else {
    return winBidResult.filter((item) => item.rankNo)
  }
}

const handleSave = async () => {
  const apiData = cloneDeep(formData.value)
  apiData.mediaNameSelect = apiData.mediaNameSelect.join(',')
  await updateReviewReportDynamicValue(apiData)
  await initData()
}
defineExpose({
  formData
})
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
